<?php

namespace App\Http\Controllers\Api\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Api\Home\BaseController;
use App\Models\Namecard;

class NamecardController extends BaseController
{
    private $return = array(
        'code' => 1,
        'msg' => ''
    );

    /**
     * [index description]
     * @param  Request  $request  [description]
     * @param  Namecard $namecard [description]
     * @return [type]             [description]
     */
    public function index(Request $request,Namecard $namecard){
        $pageSize = $request->input('pageSize',$this->pageSize);
        $map = $request->all();
        $result = $namecard->getDataByMap($map,$pageSize);
        $this->return['code'] = 0;
        $this->return['data'] = $result;
        return response()->json($this->return);
    }


    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
     public function show($id,Namecard $namecard)
     {
        $result = $namecard->getDataById($id);
        $this->return['code'] = 0;
        if(!$result){
            $this->return['msg'] = '查询失败！';
        }else{
            $this->return['code'] = 0;
            $this->return['data'] = $result;
        }
        return response()->json($this->return);
     }

}
